<?php
/*
 module:		红娘管理
 create_time:	2022-03-08 11:13:01
 author:		
 contact:		
*/

namespace app\backend\service;

use app\backend\model\ZhMatchmakerAddinfo;
use app\backend\model\Member;
use app\backend\model\ZhMatchmaker;
use think\exception\ValidateException;
use xhadmin\CommonService;

class ZhMatchmakerAddinfoService extends CommonService
{


    /*
     * @Description  列表数据
     */
    public static function indexList($where, $limit, $page)
    {
        try {
            $res = ZhMatchmakerAddinfo::alias('a')->leftJoin('zh_matchmaker m','a.matchmaker_id=m.matchmaker_id')->where($where)->field(["a.id,a.status,a.content,a.photos,a.createtime,m.name,m.phone"])->order(['a.createtime' => 'desc'])->paginate(['list_rows' => $limit, 'page' => $page])->toArray();
            foreach ( $res['data'] as &$r){
                $r["content"]=mb_substr($r["content"],0,15);
                $r['has_photo'] = 0;
                if($r['photos']!="null"&&count($r['photos'])>0){
                    $r['has_photo'] = 1;
                }

            }
        } catch (\Exception $e) {
            abort(config('my.error_log_code'), $e->getMessage());
        }
        return ['rows' => $res['data'], 'total' => $res['total']];
    }

    public static function byId($id)
    {
        try {
            $res = ZhMatchmakerAddinfo::where(['id'=>$id])->find();
        } catch (\Exception $e) {
            abort(config('my.error_log_code'), $e->getMessage());
        }
        return $res;
    }

    /*
     * @Description  修改
     */
    public static function update($data)
    {
        try {
            $res                = ZhMatchmakerAddinfo::update($data);
        } catch (ValidateException $e) {
            throw new ValidateException ($e->getError());
        } catch (\Exception $e) {
            abort(config('my.error_log_code'), $e->getMessage());
        }
        if (!$res) {
            throw new ValidateException ('操作失败');
        }
        return $res;
    }


}

